home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / timr.doc < prev    next >
Text File  |  1995-03-31  |  2KB  |  48 lines

  1. Author: Joe Horn. 
  2. Here's a fun, useful and obvious program for your 48SX: 
  3.  
  4. NAME   Description                In    ->     Out 
  5.  
  6. TIMR   Level 1 object timer       obj   ->     ...  sec  obj 
  7.  
  8. [# 4181h, 80 w/ name] -- see pg. 627 for character translations 
  9.  
  10. \<< \-> p 
  11.   \<< MEM CLEAR TICKS p EVAL TICKS 
  12.       DEPTH ROLL - B\->R 8192 / 4 RND p 
  13.   \>> 
  14. \>>  @ end of TIMR 
  15.  
  16. To use TIMR, place the object to be timed in level 1 and press TIMR. 
  17.   Note: if the object requires arguments, you must include them with 
  18.   it in a list or program. 
  19.  
  20. Example:  How long does it take the 48SX to calculate the factorial 
  21.   of 253?  Place { 253 ! } in level 1, and press TIMR.  My 48SX says 
  22.   it takes .1119 seconds.  The object is left unchanged in level 1 so 
  23.   that you can press TIMR again (never trust a single timing!).  The 
  24.   result(s), if any, from the object in level 1, are found in level 3 
  25.   and up.  The rest of the stack is cleared. 
  26.  
  27. Example: How long does it take the built-in summation function to add 
  28.   the numbers from 1 to 1000?  Try it: 'sigma(A=1,100,A)' and then 
  29.   press TIMR.  My 48SX takes about 14.746 seconds.  How long does a 
  30.   user-code program to do the same thing take?  Try this: << 1 2 1000 
  31.   FOR a a + NEXT >> then press TIMR.  It only takes 9.387 seconds! 
  32.   (Moral: avoid the summation function!  It's slow!) 
  33.  
  34. Notes:  The MEM is used only to force the calculator to perform its 
  35.   "house cleaning" right away; we want to time the object, not 
  36.   extraneous calculator hiccups.  The CLEAR not only gets rid of this 
  37.   unneeded MEM value but also guarantees that the object is not 
  38.   slowed down by junk in the stack.  { TICKS p EVAL TICKS } is the 
  39.   heart of the routine; you can't get closer in time to evaluating 
  40.   the object than that.  Don't forget that local variables are never 
  41.   automatically evaluated; references to their names merely recall 
  42.   their contents to the stack.  Hence the necessity of the EVAL here. 
  43.  
  44. joehorn@hpcvbbs.UUCP  or (714) 858-0920 
  45.  
  46. P.S.  This program is obsoleted by the XTIME function in Donnelly's 
  47.       Tool Library. 
  48.